package map;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 */
public class MapDemo2 {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("语文", 120);
        map.put("数学", 135);
        map.put("英语", 135);
        map.put("物理", 100);
        map.put("生物", 85);
        map.put("地理", 85);

        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            System.out.println("key:" + key);
        }
        System.out.println("lambda表达式写法:");
        map.forEach((v, k) -> System.out.println(k +":"+v));

        System.out.println("-------");

        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        for (Map.Entry<String, Integer> entry : entrySet) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key + ":" + value);
        }

        System.out.println("-------");

        Collection<Integer> values = map.values();
        for (Integer value : values) {
            System.out.println("value" + value);
        }

        System.out.println("-------");
        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        c.forEach(e -> System.out.println(e));

    }
}





